<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    :fullscreen="true"
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <div slot="footer" class="dialog-footer">
      <a-button type="primary" @click="handleRefer" :loading="disableSubmit">引用</a-button>
      <a-button @click="handleCancel">取消</a-button>
      <a-button type="primary" @click="handleOk" :loading="disableSubmit">确定</a-button>
    </div>
    <erp-goods-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></erp-goods-form>
  </j-modal>
</template>

<script>
import ErpGoodsForm from './ErpGoodsForm'
export default {
  name: 'ErpGoodsModal',
  components: {
    ErpGoodsForm,
  },
  data() {
    return {
      title: '',
      categoryNo: '',
      categoryName: '',
      width: 896,
      visible: false,
      disableSubmit: false,
    }
  },
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {
        console.log('种类' + this.category)
        this.$refs.realForm.model.categoryNo = this.categoryNo
        this.$refs.realForm.model.categoryName = this.categoryName
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    copy(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.copy(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.submitForm()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    handleRefer() {
      this.$refs.realForm.handleRefer()
    }
  },
}
</script>